<template>
  <!-- 统计图表 -->
  <div ref="myChart" id="myChart" style="height:300px"></div>

</template>
<script>
import * as echarts from 'echarts'
export default {
  components: {},
  props: {
    datas: {
      type: Array,
      default: () => { }
    },
    obj: {
      type: Object,
      default: () => { }
    }
  },
  data() {
    return {
      myChart: null
    };
  },
  computed: {},
  watch: {
    datas: {
      handler() {
        this.init();
      },
      deep: true
    }
  },
  mounted() {
    const that = this;
    that.init();
    window.onresize = () => {
      that.myChart.resize();
    }

  },
  methods: {
    init() {
      const option = {
        tooltip: {
          trigger: 'item'
        },
        title: {
          text: this.title,
          left: 'center',
          top: '0',
          textStyle: {
            color: '#333333',
            fontWeight: 'bold',
            fontSize: 16
          }
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        xAxis: {
          type: 'category',
          data: this.datas.xAxisData,
          axisLabel: {
            show: true,
            margin: 13,
          }
        },
        yAxis: {
          type: 'value',
          name: '',
          offset: 20,
          nameTextStyle: {
            fontSize: 12,
            color: '#556677',
            padding: [0, 0, 0, 20],    // 四个数字分别为上右下左与原位置距离
            lineHeight: 28
          }
        },
        splitArea: {           // 分隔线
          show: false,
        },
        grid: {
          left: '5%',
          // top:'20%',
          right: '0%',
          bottom: '3%',
          containLabel: true,
        },
        series: [
          {
            data: this.datas.yAxisData,
            type: 'bar',
            showBackground: true,
            barWidth: '50px',//柱图宽度
            fontSize: 12,
            backgroundStyle: {
              show: false,
            },
            color: ['#55BDC6','red']
          }
        ]
      };
      if (!this.myChart) {
        this.myChart = echarts.init(this.$refs.myChart);
      }
      // 绘制图表
      this.myChart.setOption(option)
    }

  }
};
</script>
<style lang="sess" scoped>
</style>